package com.supeng.PMdepot.util;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.supeng.PMdepot.R;


/**
 * Created by Administrator on 2018/10/23.
 * Glide图片加载方法
 */

public class ImageLoaderUtil {

    /***
     * 加载圆角图片
     * @param context
     * @param url
     * @param imageView
     * @param placeholderColor
     */
    public static void loadRoundImage(Context context, String url, ImageView imageView,int placeholderColor) {
        if(placeholderColor==0){
            placeholderColor=R.color.white;
        }
        Glide.with(context)
                .load(url)
                .placeholder(placeholderColor)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .transform(new CenterCrop(context),new GlideRoundTransform(context,10))
                .into(imageView);
    }

    /***
     * 加载图片
     * @param context
     * @param url
     * @param imageView
     * @param placeholderColor
     */
    public static void loadImage(Context context, String url, ImageView imageView,int placeholderColor){
        if(placeholderColor==0){
            placeholderColor=R.color.white;
        }
        Glide.with(context)
                .load(url)
                .placeholder(placeholderColor)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(imageView);
    }

    /***
     * 加载裁剪图片
     * @param context
     * @param url
     * @param imageView
     * @param placeholderColor 占位颜色
     * @param width 宽
     * @param height 高
     */
    public static void loadImageCrop(Context context, String url, ImageView imageView,int placeholderColor,int width,int height){
        if(placeholderColor==0){
            placeholderColor=R.color.white;
        }
        Glide.with(context)
                .load(url)
                .placeholder(placeholderColor)
                .override(width, height)
                .centerCrop()
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(imageView);
    }

    public static void loadImage(Context mContext,String path,ImageView imageView){
        Glide.with(mContext)
                .load(path)
                .centerCrop()
                .placeholder(R.color.color_f6)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(imageView);
    }
    public static void loadImage480(Context context,String url,ImageView ivTop){
        Glide.with(context)
                .load(url)
                .placeholder(R.color.text_color_gray)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .override(480, 800)
                .centerCrop()
                .into(ivTop);
    }

}
